import { BadRequestException, PipeTransform } from '@nestjs/common'

// 转换为浮点数
export class ParseFloatPipe implements PipeTransform<string, Promise<number>>{
   async transform(value: string): Promise<number> {
    const val = parseFloat(value)
    if(isNaN(val)) {
      throw new BadRequestException(`Validation failed (numeric string is expected)`, 'Bad Request')
    }
    return val
  }
}
